home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS13.ADF / FutureSound / future.asm < prev    next >
Assembly Source File  |  1986-08-05  |  12KB  |  436 lines

  1.  
  2. ************************************************************************
  3. *                                                                      *
  4. *   FUTURE.ASM                                                         *
  5. *                                                                      *
  6. *   Copyright (C) 1985, Commodore Amiga Inc.  All rights reserved.     *
  7. *                                                                      *
  8. *   Portions copyright 1986 Applied Visions, 15 Oak Ridge Road,        *
  9. *           Medford, Mass. 02155  (617) 488-3602                       *
  10. *                                                                      *
  11. ************************************************************************/
  12.  
  13. *************************************************************************
  14. *
  15. * future sound library source
  16. *   based on mylib.asm, from RKM 1.1 Vol. 2 Appendix, and Errata 1.1 disk
  17. *
  18. *   V1.0 by John Foust, for Applied Visions, 22-Jun-86.
  19. *
  20. * Source Control
  21. * ------ -------
  22. * $Header: amain.asm,v 31.3 86/06/20 18:58:00 jjf Exp $
  23. *
  24. * $Locker: john foust $
  25. *
  26. * $Log:   amain.asm,v $
  27. *
  28. ************************************************************************/
  29.  
  30.    SECTION  text,CODE
  31.  
  32.    NOLIST
  33.    include "exec/types.i"
  34.    include "exec/nodes.i"
  35.    include "exec/lists.i"
  36.    include "exec/libraries.i"
  37.    include "exec/alerts.i"
  38.    include "exec/initializers.i"
  39.    include "exec/resident.i"
  40.    include "libraries/dos.i"
  41.  
  42.    include "asmsupp.i"
  43.  
  44.    include "future.i"
  45.  
  46.    LIST
  47.  
  48.    ;------ These don't have to be external, but it helps some
  49.    ;------ debuggers to have them globally visible
  50.    XDEF   Init
  51.    XDEF   Open
  52.    XDEF   Close
  53.    XDEF   Expunge
  54.    XDEF   Null
  55.    XDEF   myName
  56.  
  57. ; These are the external Lattice C functions for FutureSound
  58. ; They were compiled with stack checking off, with '-v' on lc2.
  59.  
  60.    XDEF   FSGetSize
  61.    XDEF   FSLoadSound
  62.    XDEF   FSPlaySound
  63.    XDEF   FSStopSound
  64.  
  65.    XREF   _GetSize
  66.    XREF   _LoadSound
  67.    XREF   _PlaySound
  68.    XREF   _StopSound
  69.  
  70. ; These are used by the library for the startup code.
  71.  
  72.    XREF   _AbsExecBase
  73.  
  74.    XLIB   OpenLibrary
  75.    XLIB   CloseLibrary
  76.    XLIB   Alert
  77.    XLIB   FreeMem
  78.    XLIB   Remove
  79.  
  80.  
  81.    ; The first executable location.  This should return an error
  82.    ; in case someone tried to run you as a program (instead of
  83.    ; loading you as a library).
  84.  
  85. Start:
  86.    CLEAR   d0
  87.    rts
  88.  
  89. ;-----------------------------------------------------------------------
  90. ; A romtag structure.  Both "exec" and "ramlib" look for
  91. ; this structure to discover magic constants about you
  92. ; (such as where to start running you from...).
  93. ;-----------------------------------------------------------------------
  94.  
  95.    ; Most people will not need a priority and should leave it at zero.
  96.    ; the RT_PRI field is used for configuring the roms.  Use "mods" from
  97.    ; wack to look at the other romtags in the system
  98. MYPRI   EQU   0
  99.  
  100. initDDescrip:
  101.                ;STRUCTURE RT,0
  102.      DC.W    RTC_MATCHWORD ; UWORD RT_MATCHWORD
  103.      DC.L    initDDescrip  ; APTR  RT_MATCHTAG
  104.      DC.L    EndCode       ; APTR  RT_ENDSKIP
  105.      DC.B    RTF_AUTOINIT  ; UBYTE RT_FLAGS
  106.      DC.B    VERSION       ; UBYTE RT_VERSION
  107.      DC.B    NT_LIBRARY    ; UBYTE RT_TYPE
  108.      DC.B    MYPRI         ; BYTE  RT_PRI
  109.      DC.L    myName        ; APTR  RT_NAME
  110.      DC.L    idString      ; APTR  RT_IDSTRING
  111.      DC.L    Init          ; APTR  RT_INIT
  112.                ; LABEL RT_SIZE
  113.  
  114.  
  115.    ; this is the name that the library will have
  116. myName:      FSLIBNAME
  117.  
  118.    ; a major version number.
  119. VERSION:   EQU   1
  120.  
  121.    ; A particular revision.  This should uniquely identify the bits in the
  122.    ; library.  I use a script that advances the revision number each time
  123.    ; I recompile.  That way there is never a question of which library
  124.    ; that really is.
  125.  
  126. REVISION:   EQU   1
  127.  
  128.    ; this is an identifier tag to help in supporting the library
  129.    ; format is 'name version.revision (dd MON yyyy)',<cr>,<lf>,<null>
  130. idString:   dc.b   'future 1.0 (20 JUN 1986)',13,10,0
  131.  
  132. dosName:   DOSNAME
  133.  
  134.    ; force word allignment
  135.    ds.w   0
  136.  
  137.  
  138.    ; The romtag specified that we were "RTF_AUTOINIT".  This means
  139.    ; that the RT_INIT structure member points to one of these
  140.    ; tables below.  If the AUTOINIT bit was not set then RT_INIT
  141.    ; would point to a routine to run.
  142.  
  143. Init:
  144.    DC.L   MyLib_Sizeof   ; data space size
  145.    DC.L   funcTable      ; pointer to function initializers
  146.    DC.L   dataTable      ; pointer to data initializers
  147.    DC.L   initRoutine    ; routine to run
  148.  
  149.  
  150. funcTable:
  151.  
  152.    ;------ standard system routines
  153.    dc.l   Open
  154.    dc.l   Close
  155.    dc.l   Expunge
  156.    dc.l   Null
  157.  
  158.    ;------ my library function table
  159.    dc.l   FSGetSize
  160.    dc.l   FSLoadSound
  161.    dc.l   FSPlaySound
  162.    dc.l   FSStopSound
  163.  
  164.    ;------ function table end marker
  165.    dc.l   -1
  166.  
  167.  
  168.    ; The data table initializes static data structures.
  169.    ; The format is specified in exec/InitStruct routine's
  170.    ; manual pages.  The INITBYTE/INITWORD/INITLONG routines
  171.    ; are in the file "exec/initializers.i".  The first argument
  172.    ; is the offset from the library base for this byte/word/long.
  173.    ; The second argument is the value to put in that cell.
  174.    ; The table is null terminated
  175. dataTable:
  176.    INITBYTE   LH_TYPE,NT_LIBRARY
  177.    INITLONG   LN_NAME,myName
  178.    INITBYTE   LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  179.    INITWORD   LIB_VERSION,VERSION
  180.    INITWORD   LIB_REVISION,REVISION
  181.    INITLONG   LIB_IDSTRING,idString
  182.    DC.L   0
  183.  
  184.  
  185.    ; This routine gets called after the library has been allocated.
  186.    ; The library pointer is in D0.  The segment list is in A0.
  187.    ; And A6 holds an exec pointer.
  188.    ; If it returns non-zero then the library will be linked into
  189.    ; the library list.
  190. initRoutine:
  191.  
  192.    ;------ get the library pointer into a convenient A register, A5
  193.    move.l   a5,-(sp)
  194.    move.l   d0,a5
  195.  
  196.    ;------ save a pointer to exec
  197.    move.l   a6,ml_SysLib(a5)
  198.  
  199. ; and save an exec pointer for Lattice, too.
  200.    move.l   a6,_SysBase
  201.  
  202.    ;------ save a pointer to our loaded code
  203.    move.l   a0,ml_SegList(a5)
  204.  
  205.    ;------ open the dos library
  206.    lea   dosName(pc),a1
  207.    CLEAR   d0
  208.    CALLSYS   OpenLibrary
  209.  
  210.    move.l   d0,ml_DosLib(a5)
  211.  
  212. ; and save a Dos pointer for Lattice, too.
  213.    move.l   d0,_DOSBase
  214.    bne.s   1$
  215.  
  216.    ;------ can't open the dos!  what gives
  217.    ALERT   AG_OpenLib!AO_DOSLib
  218.  
  219. 1$:
  220.  
  221. ; Build and initialize all application-specific data.
  222.  
  223. ; Aside from having the _SysBase and _DOSBase variables set, Lattice
  224. ; code compiled with the '-v' option on pass 2 doesn't need any other
  225. ; setup - if you don't use any special Lattice functions.
  226.  
  227. ; final library cleanup before exiting Init routine.
  228. ; restore A5 to be a pointer to our library, like what we got to start.
  229. ; Since this is non-zero, we will be added to the library list.
  230.    move.l   a5,d0
  231.    move.l   (sp)+,a5
  232.    rts
  233.  
  234.  
  235. ;----------------------------------------------------------------------
  236. ; Here begins the system interface commands.  When the user calls
  237. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  238. ; into a call to the following routines (Open/Close/Expunge).  Exec
  239. ; has already put our library pointer in A6 for us.  Exec has turned
  240. ; off task switching while in these routines (via Forbid/Permit), so
  241. ; we should not take too long in them.
  242. ;----------------------------------------------------------------------
  243.  
  244.    ; Open returns the library pointer in d0 if the open
  245.    ; was successful.  If the open failed then null is returned.
  246.    ; It might fail if we allocated memory on each open, or
  247.    ; if only open application could have the library open
  248.    ; at a time...
  249.  
  250. Open:      ; ( libptr:a6, version:d0 )
  251.  
  252.    ;------ mark us as having another opener
  253.    addq.w   #1,LIB_OPENCNT(a6)
  254.  
  255.    ;------ prevent delayed expunges
  256.    bclr   #LIBB_DELEXP,ml_Flags(a6)
  257.  
  258.    move.l   a6,d0
  259.    rts
  260.  
  261.    ; There are two different things that might be returned from
  262.    ; the Close routine.  If the library is no longer open and
  263.    ; there is a delayed expunge then Close should return the
  264.    ; segment list (as given to Init).  Otherwise close should
  265.    ; return NULL.
  266.  
  267. Close:      ; ( libptr:a6 )
  268.     
  269.    ;------ set the return value
  270.    CLEAR   d0
  271.  
  272.    ;------ mark us as having one fewer openers
  273.    subq.w   #1,LIB_OPENCNT(a6)
  274.  
  275.    ;------ see if there is anyone left with us open
  276.    bne.s   1$
  277.  
  278.    ;------ see if we have a delayed expunge pending
  279.    btst   #LIBB_DELEXP,ml_Flags(a6)
  280.    beq.s   1$
  281.  
  282.    ;------ do the expunge
  283.    bsr   Expunge
  284. 1$:
  285.    rts
  286.  
  287.  
  288.    ; There are two different things that might be returned from
  289.    ; the Expunge routine.  If the library is no longer open
  290.    ; then Expunge should return the segment list (as given to
  291.    ; Init).  Otherwise Expunge should set the delayed expunge
  292.    ; flag and return NULL.
  293.    ;
  294.    ; One other important note: because Expunge is called from
  295.    ; the memory allocator, it may NEVER Wait() or otherwise
  296.    ; take long time to complete.
  297.  
  298. Expunge:   ; ( libptr: a6 )
  299.  
  300.    movem.l   d2/a5/a6,-(sp)
  301.    move.l   a6,a5
  302.    move.l   ml_SysLib(a5),a6
  303.    
  304.    ;------ see if anyone has us open
  305.    tst.w   LIB_OPENCNT(a5)
  306.    beq   1$
  307.  
  308.    ;------ it is still open.  set the delayed expunge flag
  309.    bset   #LIBB_DELEXP,ml_Flags(a5)
  310.    CLEAR   d0
  311.    bra.s   Expunge_End
  312.  
  313. 1$:
  314.    ;------ go ahead and get rid of us.  Store our seglist in d2
  315.    move.l   ml_SegList(a5),d2
  316.  
  317.    ;------ unlink from library list
  318.    move.l   a5,a1
  319.    CALLSYS   Remove
  320.    
  321. ; now perform application-specific cleanup
  322.  
  323. ; nothing to clean up from Lattice as specified above.
  324.  
  325. ; continue the library cleanup
  326.  
  327.    ;------ close the dos library
  328.    move.l   ml_DosLib(a5),a1
  329.    CALLSYS   CloseLibrary
  330.  
  331.    ;------ free our memory
  332.    CLEAR   d0
  333.    move.l   a5,a1
  334.    move.w   LIB_NEGSIZE(a5),d0
  335.  
  336.    sub.l   d0,a1
  337.    add.w   LIB_POSSIZE(a5),d0
  338.  
  339.    CALLSYS   FreeMem
  340.  
  341.    ;------ set up our return value
  342.    move.l   d2,d0
  343.  
  344. Expunge_End:
  345.    movem.l   (sp)+,d2/a5/a6
  346.    rts
  347.  
  348.  
  349. Null:
  350.    CLEAR   d0
  351.    rts
  352.  
  353. ;----------------------------------------------------------------------
  354. ; Here begins the library specific commands
  355. ;----------------------------------------------------------------------
  356.  
  357. ; Lattice places the function arguments on the stack in right-to-left
  358. ; declaration order, so the CALLED function takes them off in natural
  359. ; order.  So, here we take the register values as specified in
  360. ; 'future_lib.fd,' and put them on the stack for Lattice.
  361.  
  362. ; Lattice function return values are in D0 in these functions
  363.  
  364.  
  365. ; ULONG GetSize(filename)        (A0)
  366. ; char *filename;
  367. ;
  368. ; ULONG error code returned in D0.L
  369.  
  370. FSGetSize:
  371.    move.l   a0,-(a7)
  372.    jsr      _GetSize
  373.    add.w     #4,a7
  374.    rts
  375.  
  376. ; UWORD LoadSound(filename,buffer)  (D0,A0)
  377. ; char *filename;
  378. ; char *buffer;
  379. ;
  380. ; recording rate returned in D0
  381.  
  382. FSLoadSound:
  383.    move.l   a0,-(a7)
  384.    move.l   d0,-(a7)
  385.    jsr      _LoadSound
  386.    add.w    #8,a7
  387.    rts
  388.  
  389. ; struct IOAudio *PlaySound(buffer,buflen,repeat,period,volume) (A0,D0-D3)
  390. ; BYTE *buffer;
  391. ; ULONG buflen;
  392. ; long repeat,
  393. ;      period,
  394. ;      volume;
  395. ; struct IOAudio pointer returned in D0.L
  396.  
  397. FSPlaySound:
  398.    movem.l  d0/d1/d2/d3,-(a7)    ; D3 is pushed first
  399.    move.l   a0,-(a7)
  400.    jsr      _PlaySound
  401.    add.w    #20,a7
  402.    rts
  403.  
  404.  
  405. ; StopSound(ioa)        (A0)
  406. ; struct IOAudio *ioa;
  407. ;
  408. ; no return value
  409.  
  410. FSStopSound:
  411.    move.l   a0,-(a7)
  412.    jsr      _StopSound
  413.    moveq    #0,d0
  414.    add.w    #4,a7
  415.    rts
  416.  
  417. ; Lattice data for these functions.
  418.  
  419.    XDEF   _DOSBase,_SysBase
  420.  
  421. _SysBase     DC.L 0
  422. _DOSBase     DC.L 0   
  423.  
  424.    ; EndCode is a marker that show the end of your code.
  425.    ; Make sure it does not span sections nor is before the
  426.    ; rom tag in memory!  It is ok to put it right after
  427.    ; the rom tag -- that way you are always safe.  I put
  428.    ; it here because it happens to be the "right" thing
  429.    ; to do, and I know that it is safe in this case.
  430. EndCode:
  431.  
  432.    END
  433.  
  434.